package org.moonlight.jvm.instructions.stores.xastore;

import org.moonlight.jvm.instructions.base.NoOperandsInstruction;
import org.moonlight.jvm.rtda.share.Object;

/**
 * x_a_store指令: 按索引给数组元素赋值
 *               这条指令需要三个操作数:
 *                 1. 要赋给数组元素的值
 *                 2. 数组索引
 *                 3. 数组引用
 *               依次从操作数栈中弹出
 *
 * @author Moonlight
 * @createTime 2023/9/15 15:02
 **/
public abstract class XAStore extends NoOperandsInstruction {

    protected void checkNotNull(Object ref) {
        if (ref == null) {
            throw new NullPointerException();
        }
    }

    protected void checkIndex(int arrLen, int idx) {
        if (idx < 0 || idx >= arrLen) {
            throw new ArrayIndexOutOfBoundsException();
        }
    }
}
